/**
 * 
 */
package org.chengsen.zhang.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

/**
 * @author Jason.zhang
 * 
 */
public class FileUtil {
	/**
	 * 
	 * @param file
	 * @return
	 * @throws IOException
	 */
	public static List<String> readFile(File file) throws IOException {
		List<String> lineList = new ArrayList<String>();
		if (!file.exists()) {
			return lineList;
		}
		BufferedReader reader = new BufferedReader(new FileReader(file));
		String line = StringUtils.EMPTY;
		while ((line = reader.readLine()) != null) {
			lineList.add(line);
		}
		return lineList;
	}

	public static void writeFile(File file, String fileContent) {
		Writer writer = null;

		try {
			writer = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream(file), "utf-8"));
			writer.write(fileContent);
		} catch (IOException ex) {
			// report
		} finally {
			try {
				writer.close();
			} catch (Exception ex) {
			}
		}
	}
}
